import { API_LIST } from '../../Api/Api'
import { setValueEnumData } from '../../Router/MenuBoxList'
import { TwoAddBtn, ThrDeleteBtn, SeeEnclosure } from '../options'

export const EnterpriseImage = async ({ upDataEvent, data }) => {
    let dataList = {
        type: '企业图片管理',
        hideInSearch: true,
        pageSize: 10,
        params: {},
        classification: 'TableModal',
        get: API_LIST([data.uuid])['getEnterpriseEnterpriseImages'],
        options: [
            <TwoAddBtn
                upDataEvent={upDataEvent}
                title="添加图片信息"
                ThrKey="ThrModal"
                value="EnterpriseImage"
                data={data}
            />,
        ],
        columns: [
            {
                dataIndex: 'tableName',
                title: '图片标题',
                valueType: 'input',
            },
            {
                dataIndex: 'enterpriseImageCategoryUuid',
                title: '图片类别',
                valueType: 'select',
                valueEnum: {},
                rules: true,
                width: 350,
                className: 'RemarkForm',
            },

            {
                title: '创建时间',
                dataIndex: 'createTime',
                valueType: 'input',
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { attachment, uuid } = record
                    return [
                        attachment?.fileUrl && (
                            <SeeEnclosure
                                key="see"
                                title="查看附件"
                                data={{
                                    className: 'Admin',
                                    url: attachment.fileUrl,
                                }}
                            />
                        ),
                        <ThrDeleteBtn
                            key="delete"
                            additional={[uuid]}
                            record={data.uuid}
                            upDataEvent={upDataEvent}
                            data={{ key: 'delete', url: 'delEnterpriseEnterpriseImages', title: '删除图片信息' }}
                        />,
                    ]
                },
            },
        ],
    }
    dataList.columns.find(v => v.dataIndex === 'enterpriseImageCategoryUuid').valueEnum = await setValueEnumData({
        url: 'getEnterpriseImageCategory',
    })
    return dataList
}
